(function() {
    'use strict';

    angular
        .module('lighter')
        .factory('nodeAPIservice', nodeAPIservice);

        /** @ngInject */
        function nodeAPIservice($http) {
            var nodeAPI = {};
            nodeAPI.getTopics = function() {
                var path = 'https://cnodejs.org/api/v1/topics';
                return $http({
                    method: 'GET',
                    url: path,
                    params: {
                        page: 1,
                        tab: 'ask',
                        limit: 1000,
                        mdrender: false
                    }
                });
            }

            nodeAPI.getTopicDtails = function(id) {
                var path = 'https://cnodejs.org/api/v1/topic/' + id;
                return $http({
                    method: 'GET',
                    url: path,
                    params: {
                        mdrender: false,
                        accessToken: 'lighter'
                    }
                });
            }

            nodeAPI.newTopics = function() {
                var path = 'https://cnodejs.org/api/v1/topics';
                return $http({
                    method: 'POST',
                    url: path,
                    data: {
                        accessToken: 'lighter',
                        title: 'mylit',
                        tab: 'share',
                        content: '我就是测试一下而已！lighter'
                    }
                });
            }

            return nodeAPI;
        }

})();